package member.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		1. 로그인 체크
		HttpSession session = request.getSession();
		Object mem = session.getAttribute("login_member");
//		2. 처리
		String url = null;
		if(mem!=null){
//		2-1. 로그인 한 클라이언트의 경우 - 로그아웃 처리(Session 소멸)
		url = "/member/logout_success.jsp";
		session.invalidate();	
		}else{
//		2-2. 로그인 안한 클라이언트의 경우
		url = "/member/login_form.jsp";
		request.setAttribute("error_message", "로그인한 적이 없습니다.");
		}
		RequestDispatcher rdp = request.getRequestDispatcher(url);
		rdp.forward(request, response);
	} 
	

}
